package projectServlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.DAOException;
import dao.LeaveDAOFactory;
import dao.mysql.LeaveDAOFactoryImpl;
//import dao.mysql.LeaveDAOImpl;
//import dao.mysql.LeaveDAOFactoryImpl;
import dto.LeaveDTO;

/**
 * Servlet implementation class viewdetail
 */
@WebServlet(description = "viewdetailforstaff", urlPatterns = { "/viewdetail" })
public class viewdetail extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public viewdetail() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		
		doprocess(request, response);		
	}

	private void doprocess(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		//int nm =1002;
		//HttpSession session = request.getSession();
		//LoginDTO login=(LoginDTO)session.getAttribute("USERSESSION");
		//int staffid=login.getStaffId();

			String SID = (String) request.getSession().getAttribute("id");		
			int nm = Integer.parseInt(SID);


		LeaveDAOFactory LFactory = new LeaveDAOFactoryImpl();
		ArrayList<LeaveDTO> Leave = new ArrayList<LeaveDTO>();
		//Leave.add()
	try {
			Leave = LFactory.getLeaveDAO().getLeaveHistory(nm);
			
		} catch (DAOException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		}
		//int userID = session.getAttribute("USERID");
		
	   	   
		request.setAttribute("LeaveInfo", Leave);
		RequestDispatcher rd = request.getRequestDispatcher("viewdetail.jsp");
		rd.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doprocess(request, response);	// TODO Auto-generated method stub
	}

}
